package Sequence;

public class Test0538 {
}

class Solution0538_1 {
    public TreeNode convertBST(TreeNode root) {
        buildTree(root,0);
        return root;
    }

    public int buildTree(TreeNode root, int sum) {
        if (root == null) return sum;
        sum=buildTree(root.right,sum);

        root.val+=sum;
        sum=root.val;
        sum=buildTree(root.left,sum);

        return sum;
    }
}
